// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-9

#ifndef __SERVERWND_H_COMMON_SERVER__
#define __SERVERWND_H_COMMON_SERVER__

#pragma once

#include <common/ui/wnd.h>
#include <common/ui/button.h>
#include <common/ui/label.h>
#include <common/svr_base/svr_msgwnd.h>
#include "svr_server.h"
#include "ui_attribitem.h"

class CJoyServerInfoView;
class CJoyDragger;

namespace JoyServer
{
    class CJoyServerAsyncStop;
}

class CJoyServerWnd :
    public CJoyWnd
{
	DECLARE_DYNAMIC(CJoyServerWnd)
public:
    CJoyButton* m_btnStart;
    CJoyButton* m_btnStop;
    CJoyButton* m_btnExit;
    CJoyLabel*  m_statusText;
    CJoyDragger*m_dragger;

    JoyServer::CJoyServerAsyncStop*    m_asyncServerStop;

    CJoyMsgWnd  m_mainThreadWnd;

    virtual JoyServer::CJoyServer* AllocServer() = 0;
    virtual bool StartServer();
    virtual void StopServer();

    template<typename AttribType>
    void CreateAttrib(AttribType*& pAttrib)
    {
        pAttrib = new AttribType();
        m_attribView->AddItemTail(pAttrib);
    }

    virtual void OnServerStart();
    virtual void OnServerStop();

    void CM_BtnClick(CJoyButton*);
public:
    CJoyServerInfoView*     m_infoView;
    JoyServer::CJoyServer*  m_server;
    
    CJoyAttribView*     m_attribView;

    // attribute items
    JoyServerAttrib::Attrib_AppAttrib*  m_attrib_appAttrib;
    JoyServerAttrib::Attrib_ServerName* m_attrib_serverName;
    JoyServerAttrib::Attrib_ServerTime* m_attrib_serverTime;
    JoyServerAttrib::Attrib_ClientVer*  m_attrib_clientVer;
    JoyServerAttrib::Attrib_CpuTime*    m_attrib_cpuTime;
    JoyServerAttrib::Attrib_ResourceUse*m_attrib_resourceUse;
    JoyServerAttrib::Attrib_IOUse*      m_attrib_ioUse;
    JoyServerAttrib::Attrib_NetworkUse* m_attrib_networkUse;
    JoyServerAttrib::Attrib_ServerAddr* m_attrib_serverAddr;
    JoyServerAttrib::Attrib_UserCount*  m_attrib_userCount;
    JoyServerAttrib::Attrib_LogLevel*   m_attrib_logLevel;
public:
    CJoyServerWnd(void);
    virtual ~CJoyServerWnd(void);

    bool Create();
    void SetStatusText(PCSTR text);

    virtual JoyServer::CJoyServerAsyncStop* AllocAsyncStop();
	virtual void UpdateInsertAttrib(UINT roomId);//*-----------------------------------------------------updateNewRoom


public:
    DECLARE_MESSAGE_MAP()
    afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnDestroy();
    afx_msg void OnClose();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnTimer(UINT nIDEvent);
};

#endif  // __SERVERWND_H_COMMON_SERVER__